package com.coe3.datahandler;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.util.Log;

public class BaseActivity extends Activity {
	
	private ProgressDialog mProgressDialog = null;
	private ProgressDialog mDownloadDialog = null;
	
	static public final int DIALOG_CONNECTION_START = 0;
	static public final int DIALOG_DOWNLOAD_PROGRESS = 1;
	

	@SuppressWarnings("deprecation")
	@Override
    protected Dialog onCreateDialog( int id ) {
    	
        switch (id) {
            case DIALOG_CONNECTION_START:
            	Log.i("CREATE DIALOG", "DIALOG CONNECTION CREATE");
                mProgressDialog = new ProgressDialog( this );
                mProgressDialog.setIndeterminate(true);
                mProgressDialog.setMessage( " Please wait. " );
                mProgressDialog.setCancelable( false );
                mProgressDialog.show();
                
                return mProgressDialog;
                
            case DIALOG_DOWNLOAD_PROGRESS:
            	Log.i("CREATE DIALOG", "DIALOG DOWNLOAD CREATE");
            	mDownloadDialog = new ProgressDialog(this);
            	mDownloadDialog.setMessage(" Downloading ... ");
            	mDownloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            	mDownloadDialog.setCancelable(false);
            	mDownloadDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {

            	      public void onClick(DialogInterface dialog, int id) {

            	        //...
            	    	  mDownloadDialog.dismiss();
            	    } }); 
            	mDownloadDialog.setProgress(0);
            	mDownloadDialog.setMax(100);
            	mDownloadDialog.show();
                
            	return mDownloadDialog;
                
            default:
            	Log.i("CREATE DIALOG", "DIALOG DEFAULT CREATE");
                return super.onCreateDialog(id);
        }
    }
	
	public void showAlertBox( String title, int messageid ) {
		this.showAlertBox(title, this.getString(messageid));
	}
	
	public void showAlertBox( String title, String message ) {
		Log.d("chud", "title: " + title);
		Log.d("chud", "message: " + message);
		try {
			//        this.hideProgressDialog();
			AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
			alertbox.setTitle(title);
			alertbox.setMessage(message);
			alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface arg0, int arg1) {
				}
			});
			alertbox.show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	public ProgressDialog progressDialong() {
		return mProgressDialog;
	}
	
	public ProgressDialog downloadDialog() {
		return mDownloadDialog;
	}
	
	public void didFinishdownload() {
		mDownloadDialog.hide();
	}
	
	public void didFinishParsing() {
		mProgressDialog.hide();
	}
}
